﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;

namespace Elentok.Common.Wpf.ValueConverters
{
  /// <summary>
  /// converts <see cref="Boolean"/> values to <see cref="Visibility"/>
  /// </summary>
  public sealed class BooleanToVisibilityConverter : IValueConverter
  {
    /// <summary>
    /// Converts <see cref="Boolean"/> to <see cref="Visibility"/>
    /// </summary>
    /// <param name="value"></param>
    /// <param name="targetType"></param>
    /// <param name="parameter"></param>
    /// <param name="culture"></param>
    /// <returns></returns>
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      bool boolValue = (bool)value;
      return boolValue ? Visibility.Visible : Visibility.Hidden;
    }

    /// <summary>
    /// Converts <see cref="Visibility"/> to <see cref="Boolean"/>
    /// </summary>
    /// <param name="value"></param>
    /// <param name="targetType"></param>
    /// <param name="parameter"></param>
    /// <param name="culture"></param>
    /// <returns></returns>
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      Visibility visibilityValue = (Visibility)value;
      if (visibilityValue == Visibility.Visible)
        return true;
      else
        return false;
    }
  }
}
